Imports cmplib01

Public Class frmOOBEditor
    Inherits System.Windows.Forms.Form

    Const c_Module As String = "frmOOBEditor"
    Friend WithEvents btnEdit As System.Windows.Forms.Button

    Private ptrCurrentGame As CampaignerGameData

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents btnOK As System.Windows.Forms.Button
    Friend WithEvents pnlVictoryConditions As System.Windows.Forms.Panel
    Friend WithEvents lblExistingUnits As System.Windows.Forms.Label
    Friend WithEvents lstUnits As System.Windows.Forms.ListBox
    Friend WithEvents btnDelete As System.Windows.Forms.Button
    Friend WithEvents btnAdd As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmOOBEditor))
        Me.btnOK = New System.Windows.Forms.Button
        Me.pnlVictoryConditions = New System.Windows.Forms.Panel
        Me.btnAdd = New System.Windows.Forms.Button
        Me.btnDelete = New System.Windows.Forms.Button
        Me.lblExistingUnits = New System.Windows.Forms.Label
        Me.lstUnits = New System.Windows.Forms.ListBox
        Me.btnEdit = New System.Windows.Forms.Button
        Me.pnlVictoryConditions.SuspendLayout()
        Me.SuspendLayout()
        '
        'btnOK
        '
        Me.btnOK.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnOK.Location = New System.Drawing.Point(168, 384)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.Size = New System.Drawing.Size(75, 23)
        Me.btnOK.TabIndex = 6
        Me.btnOK.Text = "OK"
        '
        'pnlVictoryConditions
        '
        Me.pnlVictoryConditions.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlVictoryConditions.Controls.Add(Me.btnEdit)
        Me.pnlVictoryConditions.Controls.Add(Me.btnAdd)
        Me.pnlVictoryConditions.Controls.Add(Me.btnDelete)
        Me.pnlVictoryConditions.Controls.Add(Me.lblExistingUnits)
        Me.pnlVictoryConditions.Controls.Add(Me.lstUnits)
        Me.pnlVictoryConditions.Location = New System.Drawing.Point(8, 8)
        Me.pnlVictoryConditions.Name = "pnlVictoryConditions"
        Me.pnlVictoryConditions.Size = New System.Drawing.Size(240, 368)
        Me.pnlVictoryConditions.TabIndex = 5
        '
        'btnAdd
        '
        Me.btnAdd.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnAdd.Location = New System.Drawing.Point(12, 336)
        Me.btnAdd.Name = "btnAdd"
        Me.btnAdd.Size = New System.Drawing.Size(64, 23)
        Me.btnAdd.TabIndex = 10
        Me.btnAdd.Text = "Add"
        '
        'btnDelete
        '
        Me.btnDelete.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnDelete.Location = New System.Drawing.Point(152, 336)
        Me.btnDelete.Name = "btnDelete"
        Me.btnDelete.Size = New System.Drawing.Size(72, 23)
        Me.btnDelete.TabIndex = 9
        Me.btnDelete.Text = "Delete"
        '
        'lblExistingUnits
        '
        Me.lblExistingUnits.Location = New System.Drawing.Point(16, 5)
        Me.lblExistingUnits.Name = "lblExistingUnits"
        Me.lblExistingUnits.Size = New System.Drawing.Size(160, 16)
        Me.lblExistingUnits.TabIndex = 4
        Me.lblExistingUnits.Text = "Existing Units"
        '
        'lstUnits
        '
        Me.lstUnits.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.lstUnits.Location = New System.Drawing.Point(8, 24)
        Me.lstUnits.Name = "lstUnits"
        Me.lstUnits.Size = New System.Drawing.Size(221, 301)
        Me.lstUnits.TabIndex = 1
        '
        'btnEdit
        '
        Me.btnEdit.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnEdit.Location = New System.Drawing.Point(82, 336)
        Me.btnEdit.Name = "btnEdit"
        Me.btnEdit.Size = New System.Drawing.Size(64, 23)
        Me.btnEdit.TabIndex = 11
        Me.btnEdit.Text = "Edit"
        '
        'frmOOBEditor
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(258, 416)
        Me.Controls.Add(Me.btnOK)
        Me.Controls.Add(Me.pnlVictoryConditions)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.Name = "frmOOBEditor"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
        Me.Text = "Order Of Battle"
        Me.pnlVictoryConditions.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Public Sub New(ByRef Game As CampaignerGameData)
        Me.New()

        ptrCurrentGame = Game
        ListUnits()
    End Sub

    Private Sub ListUnits()
        Dim bg As BattlegroupChit
        Dim i As Int16

        lstUnits.Items.Clear()

        For Each bg In ptrCurrentGame.selectedFaction.OrderOfBattle
            lstUnits.Items.Add(bg)
        Next

    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        AddUnit()
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        If lstUnits.SelectedItem Is Nothing Then Exit Sub

        ptrCurrentGame.selectedFaction.OrderOfBattle.remove(DirectCast(lstUnits.SelectedItem, BattlegroupChit))
        ListUnits()

    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Me.Hide()
    End Sub

    Private Sub AddUnit()
        Try
            Dim frmAddBG As New frmOOBBG
            Dim nbg As New BattlegroupChit

            frmAddBG.ShowDialog(nbg, ptrCurrentGame)

            If frmAddBG.ActionCancelled Then Exit Sub

            nbg.OwningFaction = ptrCurrentGame.selectedFaction
            nbg.OwningPlayer = Nothing

            ptrCurrentGame.selectedFaction.OrderOfBattle.add(nbg)
            ListUnits()

        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try

    End Sub

    Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
        If lstUnits.SelectedItem Is Nothing Then Exit Sub
        Try
            Dim bg As BattlegroupChit = lstUnits.SelectedItem
            Dim f As New frmOOBBG
            f.ShowDialog(bg, ptrCurrentGame)
            ListUnits() '// in case the name has been changed 

        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try
    End Sub
End Class
